package com.hopes.bizz.risk.transfer.handler;

import cn.hutool.extra.spring.SpringUtil;
import com.hopes.bizz.risk.transfer.constant.RiskRequestType;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @author lyb
 * @version 1.0
 * @date 2024/2/2 9:25
 */

@Component
public class RiskDataHandlerFactory {

    private Map<RiskRequestType, RiskDataHandler> map = new ConcurrentHashMap<>(8);

    @PostConstruct
    public void init() {
        SpringUtil.getApplicationContext().getBeansOfType(RiskDataHandler.class).values()
                .forEach(handler -> map.put(handler.getRequestType(), handler));
    }

    public RiskDataHandler getHandlerByRequestType(RiskRequestType requestType) {
        return map.get(requestType);
    }
}
